package com.jzqf.harmonydemo.base;

import com.jzqf.harmonydemo.ResourceTable;
import com.jzqf.harmonydemo.utils.CommonUtil;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.Text;
import ohos.agp.utils.Color;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

/**
 * AbilitySclice基类
 *
 * @author LiuWeiHao
 * 2021/5/17 13:51
 */
public abstract class BaseAbilitySlice extends AbilitySlice {
    private Image mBackIv;
    private Text mTitleTv;
    private static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_APP, 0x00201, "AbilitySlice");

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(getLayoutResId());
        //沉浸式状态栏
//        getWindow().addFlags(WindowManager.LayoutConfig.MARK_TRANSLUCENT_STATUS);
        //状态栏颜色
        getWindow().setStatusBarColor(CommonUtil.getColor(this, ResourceTable.Color_color_navigation));
        //TODO 状态栏字体颜色设置
        initBaseView();
        HiLog.info(LABEL, "---baseAbilitySlice onStart");
    }

    private void initBaseView() {
        mTitleTv = (Text) findComponentById(ResourceTable.Id_actionbar_title_text);
        mBackIv = (Image) findComponentById(ResourceTable.Id_actionbar_back_iv);
        mBackIv.setClickedListener(component -> onBackPressed());
    }

    protected abstract int getLayoutResId();

    protected void setTitle(String text) {
        mTitleTv.setText(text);
    }

    protected void hideBack() {
        mBackIv.setVisibility(Component.HIDE);
    }
}
